

package com.xtsoft.platform.base.database.domain;

/*
*    上海信拓信息技术有限公司  
*    Copyright (C) ShangHai XinTuo Software Inc.
*/

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.xtsoft.core.common.Constants;
import com.xtsoft.core.common.YesNo;
import com.xtsoft.core.entity.GenericEntity;

import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.annotations.GenericGenerator;

import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
/**
 * DbConnect Base Java Bean, base class for the model, mapped directly to database table
 * 
 * Avoid changing this file if not necessary, will be overwritten. 
 *
 * TODO: add class/table comments
 */
@Entity
@Table(name = "db_connect")
@Data
public class DbConnect extends GenericEntity {


	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid")
	@Column(name="dbConnectId",nullable=false,length=32)
    private String dbConnectId;


	/**
	*   ip地址
	*/
		@Column(name="ip",nullable=false, length=32 )
	private String ip;


	/**
	*   端口
	*/
		@Column(name="port",nullable=false, length=10 )
	private Integer port;


	/**
	*   数据库名称
	*/
		@Column(name="dbName",nullable=false, length=64 )
	private String dbName;


	/**
	*   连接驱动
	*/
		@Column(name="dbDriver",nullable=false, length=64 )
	private String dbDriver;


	/**
	*   数据库类型
	*/
		@Column(name="dbType",nullable=false, length=10 )
	private Integer dbType;


	/**
	*   连接附属信息
	*/
		@Column(name="dbProperties",nullable=true, length=128 )
	private String dbProperties;


	/**
	*   用户名
	*/
		@Column(name="username",nullable=false, length=64 )
	private String username;


	/**
	*   密码
	*/
		@Column(name="password",nullable=true, length=128 )
	private String password;
		/**
		 * url
		 */
		@Column(name = "url", nullable = false, length = 128)
		private String url;

		/**
		 * 可连接状态 0、不可连接 1、可连接
		 */
		@Column(name = "state", nullable = false, length = 10)
		private Integer state;

	/**
	*   说明
	*/
		@Column(name="descript",nullable=true, length=255 )
	private String descript;
	
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "dbConnect")
	@JsonIgnore
	private List<DbSql> dbSqls=new ArrayList<>();

	/**
	*  默认构造
	*/
	public DbConnect(){
	
	}

	/**
	*  构造方法，自动测试使用，把除主键外的所有非空字段赋值
	*
	*  也可作普通使用  调用该构造方法时，字串参数填或不填均
	*  可，该带参构造方法仅为区别Lombok自动生成的默认构造方
	*  法。
	*  
	*  应用程序可根据需要修改该构造方法中的非空属性赋值。
	**/
	public DbConnect(String forAutoTest){

		this.ip = "New string";


		this.port = YesNo.Yes.getIntValue();


		this.dbName = "New string";


		this.dbDriver = "New string";


		this.dbType = YesNo.Yes.getIntValue();


		this.username = "New string";

	}

	/**
	 * @see Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this)
				.append("dbConnectId", this.dbConnectId) 
				.append("ip", this.ip) 
				.append("port", this.port) 
				.append("dbName", this.dbName) 
				.append("dbDriver", this.dbDriver) 
				.append("dbType", this.dbType) 
				.append("dbProperties", this.dbProperties) 
				.append("username", this.username) 
				.append("password", this.password) 
				.append("descript", this.descript) 
				.toString();
	}
	
	/**
	 * 以实体类主键生成HASHCODE
	 */
	@Override  
	public int hashCode() {  
	    return this.dbConnectId.hashCode();  
	} 	 
	
	/**
	 * 以实体类主键比较对象是否相等
	 */
	@Override  
	public boolean equals(Object obj) {  
	    if (obj instanceof DbConnect) {  
	        return this.dbConnectId.equals(((DbConnect) obj).getDbConnectId());  
	    }  
	    return false;  
	}	 
	
}
